package jp.sourceforge.akjrcp.util;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import jp.sourceforge.akjrcp.flvtools.basic.FLVUtil;

public class FLVChecker {
private int keepSize=1000;
private Map fileMap=new HashMap();
public class FLVCheckStatus{
	private boolean flvFile;
	private long lastmodified;
	public boolean isFlvFile() {
		return flvFile;
	}
	public void setFlvFile(boolean flvFile) {
		this.flvFile = flvFile;
	}
	public long getLastmodified() {
		return lastmodified;
	}
	public void setLastmodified(long lastmodified) {
		this.lastmodified = lastmodified;
	}
}

public boolean checkFLV(File file){
	FLVCheckStatus status=(FLVCheckStatus) fileMap.get(file.getAbsolutePath());
	if(status!=null && status.getLastmodified()==file.lastModified()){
		return status.isFlvFile();
	}
	
	boolean isFLV=FLVUtil.isFLVFileFormat(file);
	status=new FLVCheckStatus();
	status.setFlvFile(isFLV);
	status.setLastmodified(file.lastModified());
	
	fileMap.put(file.getAbsolutePath(), status);
	if(fileMap.size()>keepSize){
		fileMap.remove(fileMap.keySet().iterator().next());
	}
	return isFLV;
}

}
